package com.allinpay.trans;

import com.allinpay.trans.bean.TransRouteRule;
import com.allinpay.trans.bizroute.BizRouteCli;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @ClassName TransactionApplication
 * @Description tranaction springboot application
 * @Author richard
 * @Date 2021/12/15 3:27 PM
 */
@SpringBootApplication
@Slf4j
public class TransactionApplication {

    public static void main(String[] args) {
        SpringApplication.run(TransactionApplication.class, args);
        log.info("TransactionApplication started");
    }

    @RestController
    @RequestMapping("/trans")
    public class TransAction{

        @Autowired
        private TransSvc transSvc;

        @GetMapping("/get")
        public TransRouteRule getTransRoute(String mcd, String tcd){
            log.info("controller get request :mcd:{},tcd:{}",
                    mcd, tcd);

            TransRouteRule transRouteRule = transSvc.chkTransRoute(mcd, tcd);

            log.info("rsp:{}",transRouteRule.toString());
            return transRouteRule;
        }

    }

    @Service
    public class TransSvc{

        @Autowired
        private BizRouteCli bizRouteCli;

        public TransRouteRule chkTransRoute(String mcd, String tcd){

            log.info("TransSvc TransRouteRule called");

//            BizRouteCli bizRouteCli = new BizRouteCli();

            return bizRouteCli.callBizRouteSvc(mcd, tcd);
        }
    }
}
